import React from 'react';
import { inject, observer } from 'mobx-react';
import TaskLogs from '../../../public/loadlog/loadLogs';
import * as Util from '../../../util/Util';
const toJS = mobx.toJS;
@inject('taskDetailStore')
@observer
export default class LogInfo extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
        }
    }
    componentWillMount() {//一些初始化请求
        const{taskDetailStore} = this.props;
        if(taskDetailStore.firstlog==1){
            taskDetailStore.getTaskLog({lastid:'', operation: 'getLog',taskId: taskDetailStore.detailKey});
            taskDetailStore.firstlog=0;
        }
    }
    componentDidMount(){
        const{taskDetailStore} = this.props;
        if(taskDetailStore.spinning){
            taskDetailStore.spinning = false;
        }
    }
    //相关信息点击和删除
    onLinkClick(id, name, type,typeIds, typeArray,fileid){
        const { taskDetailStore } = this.props;
        const {detailKey} =  taskDetailStore;
        if(type==1){
            if(typeIds=="taskids"){
                taskDetailStore.onNodeClick({key:id});
            }
            if(typeIds=="goalids"){
                window.open('/spa/workrelate/static/index.html?#/main/workrelate/goal/goalDetail?id='+id);
            }
            if(typeIds=="fileids"){
                taskDetailStore.viewDocFiled({id:id,relateId:detailKey,type:2,doback:function(){
                    Util.opendoc(id);
                }});
            }
        }
    }
    
    //操作日志加载更多
    onMoreClick(pagesize, type) {
        const { taskDetailStore } = this.props;
        taskDetailStore.getTaskLog({ taskId: taskDetailStore.detailKey, pagesize: pagesize, lastid: taskDetailStore.lastid, operation: 'getLog', type: type });
    }
    render() {
        const { taskDetailStore:{hasData,taskLog,lastcount}} = this.props;
        return (
            <div>
                { hasData &&  <TaskLogs ecId={`${this && this.props && this.props.ecId || ''}_TaskLogs@r2mrku`} logsData={toJS(taskLog)} lastcount={lastcount} onMoreClick={() => this.onMoreClick('', 'more')} onLinkClick={(id, name, type,columninfo)=>this.onLinkClick(id, name, type,columninfo)}/>}
            </div >
        )
    }
};